package com.example.demo;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2023-02-12
 * Time:20:36
 */
//登录页面
@RestController
@RequestMapping("/user")
public class Login {
    @RequestMapping("/login")
    public boolean login(HttpServletRequest request, String username, String password){
        if (StringUtils.hasLength(username)&&StringUtils.hasLength(password)){
            //判断账号密码：假设为zhangsan，
            if("zhangsan".equals(username)&&"zhangsan".equals(password)){
                //创建会话session
                HttpSession session=request.getSession();
                session.setAttribute("userinfo","zhangsan");
                return true;
            }else {
                return false;
            }
        }
        return false;
    }
}
